R debugging

If received an error message, one can use taceback function to find out in which function the bug is:

> traceback()

After located the specific function, one can use debug funtion to find the specific line of code containing bug. For example, the function name is SS.

> debug(SS)
> SS(2, x)

Browser[1]>

One is now in what is called the "browser". Here one can enter 1 of 4 basic debug commands (n, c, where, Q).

<Enter>
    Go to the next statement if the function is being debugged. Continue
    execution if the browser was invoked.

c or cont
    Continue execution without single stepping.

n
    Execute the next statement in the function. This works from the browser as
    well.

where
    Show the call stack.

Q
    Halt execution and jump to the top-level immediately.  To view the value of
    a variable whose name matches one of these commands, use the print()
    function, e.g. print(n).

One can use debug(the_2nd_level_function) to go deeper.

References

Homepage
Comments

Hide Comments